{extend name="./tpl/default/mobile/public/layout.html" /}
{block name="header"}

<link rel="stylesheet" href="/public/home/mobile/css/guanjian/anli.css">
<link rel="stylesheet" href="/public/home/mobile/css/guanjian/gonglv.css">
<link rel="stylesheet" href="/public/home/mobile/css/guanjian/shouhuodizhi.css">
{/block}
{block name="head"}
<div class="am-g" style="overflow: hidden;
           white-space: nowrap;
          text-overflow: ellipsis;height: 34px;margin-top: 10px;">
    <div class="am-u-sm-8">
        <span class="icon iconfont icon-xiangzuojiantou" onclick="history.back(-1)"></span>
    </div>
    <div class="am-u-sm-4">
        收货地址<a href="{:url('/home/User/addressAdd')}" style="margin-left: 15px;">+</a>
    </div>

</div>


<hr style="border:1px solid #e0e0e0;margin: 0px;">
{/block}
{block name="body"}
<ul class="address-list" id="addressList">
    {volist name="list" id="vo"}
    <li>
        <div class="info">
            <div class="row">
                <span class="iconfont icon-wodejuhuasuan"></span>
                {$vo.consignee}
                <span class="am-fr">
                    <span class="iconfont icon-phone"></span>
                    {$vo.tel_phone}
                </span>
            </div>
            <div class="row">
                <span class="iconfont icon-yunshuzhongwuliu-xianxing"></span>
                {$vo.address_text}{$vo.address}
            </div>
            <div class="row">
                <span class="iconfont icon-mail"></span>
                {$vo.zip_code}
            </div>
        </div>
        <div class="action">
            {eq name="vo.is_default" value="1" }
            <a class="a_c active" style="cursor:pointer" data-addressid="{$vo.address_id}">
                <span class="iconfont icon-fangxingweixuanzhong"></span>
                默认地址
            </a>
            {else/}
            <a class="a_c" style="cursor:pointer" onclick="setDefault(this)" data-addressid="{$vo.address_id}">
                <span class="iconfont icon-fuxuan"></span>
                设为默认
            </a>
            {/eq}
            <a class="a_a am-fr" style="cursor:pointer" href="{:url('/home/User/addressAdd',['address_id'=>$vo['address_id']])}">
                <span class="iconfont icon-editor"></span> 编辑
            </a>
            <a class="a_b am-fr" style="cursor:pointer" onclick="delAddress(this)" data-addressid="{$vo.address_id}">
                <span class="iconfont icon-empty" ></span> 删除
            </a>
        </div>
    </li>
    {/volist}
</ul>
{/block}
{block name="script"}
<script>
    function setDefault(obj) {
        var dom = $(obj);
        $.post('{:url("/home/User/addressDefault")}', {address_id: dom.data('addressid')}, function (data) {
            layer.open({
                content: data.msg
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
                , end: function () {
                    $('.a_c').each(function () {
                        $(this).removeClass('active').attr('onclick', 'setDefault(this)').empty().append('<span class="iconfont icon-fuxuan"></span>设为默认');
                    });
                    dom.addClass('active').attr('onclick', '').empty().append('<span class="iconfont icon-fangxingweixuanzhong"></span>默认地址')
                }
            });
        })
    }

    function delAddress(obj) {
        var dom = $(obj);
        $.post('{:url("/home/User/addressDel")}', {address_id: dom.data('addressid')}, function (data) {
            layer.open({
                content: data.msg
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
                , end: function () {
                    if (data.code){
                        dom.parents('li').remove();
                    }
                }
            });
        })
    }
</script>
{/block}
